﻿namespace XUCore.WeChat.Enterprise.Net.ServerMessages.From
{
    using Newtonsoft.Json;
    using System.Collections.Generic;
    using System.Xml.Serialization;
    using XUCore.WeChat.Net.ServerMessages.From;

    /// <summary>
    /// 客户群创建事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalChatCreateEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalChatCreateEvent"/> class.
        /// </summary>
        public FromChangeExternalChatCreateEvent()
        {
            Event = FromEventTypes.change_external_chat;
            ChangeType = ChangeExternalChatChangeType.create;
        }

        /// <summary>
        /// 客户群创建事件
        /// </summary>
        public ChangeExternalChatChangeType ChangeType { get; set; }

        /// <summary>
        /// 群ID
        /// </summary>
        [XmlElement("ChatId")]
        public string ChatId { get; set; }
    }

    /// <summary>
    /// 客户群变更事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalChatUpdateEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalChatUpdateEvent"/> class.
        /// </summary>
        public FromChangeExternalChatUpdateEvent()
        {
            Event = FromEventTypes.change_external_chat;
            ChangeType = ChangeExternalChatChangeType.update;
        }

        /// <summary>
        /// 客户群变更事件
        /// </summary>
        public ChangeExternalChatChangeType ChangeType { get; set; }

        /// <summary>
        /// 群ID
        /// </summary>
        [XmlElement("ChatId")]
        public string ChatId { get; set; }

        /// <summary>
        /// 变更详情。目前有以下几种：
        /// add_member : 成员入群
        /// del_member : 成员退群
        /// change_owner : 群主变更
        /// change_name : 群名变更
        /// change_notice : 群公告变更
        /// </summary>
        [XmlElement("UpdateDetail")]
        public string UpdateDetail { get; set; }

        /// <summary>
        /// 当是成员入群时有值。表示成员的入群方式
        /// 0 - 由成员邀请入群（包括直接邀请入群和通过邀请链接入群）
        /// 3 - 通过扫描群二维码入群
        /// </summary>
        [XmlElement("JoinScene")]
        public int JoinScene { get; set; }

        /// <summary>
        /// 当是成员退群时有值。表示成员的退群方式
        /// 0 - 自己退群
        /// 1 - 群主/群管理员移出
        /// </summary>
        [XmlElement("QuitScene")]
        public int QuitScene { get; set; }

        /// <summary>
        /// 当是成员入群或退群时有值。表示成员变更数量
        /// </summary>
        [XmlElement("MemChangeCnt")]
        public int MemChangeCnt { get; set; }

        /// <summary>
        /// 当是成员入群或退群时有值。变更的成员列表
        /// </summary>
        [XmlArrayItem("Item")]
        public List<string> MemChangeList { get; set; }

        /// <summary>
        /// 当是成员入群或退群时有值。 变更前的群成员版本号
        /// </summary>
        [XmlElement("LastMemVer")]
        public string LastMemVer { get; set; }

        /// <summary>
        /// 当是成员入群或退群时有值。变更后的群成员版本号
        /// </summary>
        [XmlElement("CurMemVer")]
        public string CurMemVer { get; set; }
    }

    /// <summary>
    /// 客户群解散事件
    /// </summary>
    [XmlRoot("xml")]
    public class FromChangeExternalChatDismissEvent : FromEventBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FromChangeExternalChatDismissEvent"/> class.
        /// </summary>
        public FromChangeExternalChatDismissEvent()
        {
            Event = FromEventTypes.change_external_chat;
            ChangeType = ChangeExternalChatChangeType.dismiss;
        }

        /// <summary>
        /// 客户群解散事件
        /// </summary>
        public ChangeExternalChatChangeType ChangeType { get; set; }

        /// <summary>
        /// 群ID
        /// </summary>
        [XmlElement("ChatId")]
        public string ChatId { get; set; }
    }

    /// <summary>
    /// 客户群创建事件
    /// </summary>
    public enum ChangeExternalChatChangeType
    {
        /// <summary>
        /// 客户群创建事件
        /// </summary>
        create = 1,
        /// <summary>
        /// 客户群变更事件
        /// </summary>
        update = 2,
        /// <summary>
        /// 客户群解散事件
        /// </summary>
        dismiss = 3
    }
}
